package cn.com.freelibra.forum.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.com.freelibra.forum.dao.EmailCatchaMapper;
import cn.com.freelibra.forum.po.EmailCatcha;
import cn.com.freelibra.forum.po.EmailCatchaExample;
import cn.com.freelibra.forum.service.EmailCatchaService;

@Service("emailCatchaService")  
public class EmailCatchaServiceImpl implements EmailCatchaService{

	@Resource
	EmailCatchaMapper dao;

	@Override
	public int saveEmailCatcha(EmailCatcha emailCaptcha) {
		return dao.insert(emailCaptcha);
	}

	@Override
	public void updateEmailCatcha(EmailCatcha emailCaptcha) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<EmailCatchaService> byEmail(String email) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean activationEmail(String userName, String emailcatch) {
		// TODO Auto-generated method stub
		EmailCatchaExample  emailCatchaExample = new EmailCatchaExample();
		emailCatchaExample.createCriteria().andCaptchaEqualTo(emailcatch).andUserNameEqualTo(userName);
		if(dao.selectByEntity(emailCatchaExample).size()>0)
		{
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean deleteEmailCatcha(String userName) {
		// TODO Auto-generated method stub
		EmailCatchaExample emailCatchaExample = new EmailCatchaExample();
		emailCatchaExample.createCriteria().andUserNameEqualTo(userName);
		if(dao.deleteByEntity(emailCatchaExample)>0)
		{
			return true;
		}else{
			return false;
		}
	}
}
